from django.conf.urls.defaults import *
from django.conf import settings
from os import path

from track.models import Vehicle
from track.models import Itinerary

coord = r'-?\d+(\.\d{1,6})?'

vehicle_info_dict = {
  'queryset':             Vehicle.objects.all(),
  'paginate_by':          10,
  'template_object_name': 'vehicle',
  'template_name':        'track/index.html'
}

itinerary_info_dict = {
  'queryset':             Itinerary.objects.all().select_related(),
  'template_object_name': 'itinerary',
  'template_name':        'track/itinerary.html'
}

slugRegexp      = r'[a-zA-Z0-9_\-]+'
vehicleRegexp   = r'(?P<vehicle>' + slugRegexp + r')'
itineraryRegexp = r'(?P<itinerary>' + slugRegexp + r')'

urlpatterns = patterns('',
  # AJAX APIs to retrieve existing itineraries, vehicles,
  # and the vehicles' current positions
  (r'^ajax/itineraries/$',  'track.ajax.itineraries'),
  
  # Get list of checkpoints for an itinerary
  (r'^ajax/checkpoints/' + itineraryRegexp + r'/$', 'track.ajax.checkpoints'),
  
  (r'^ajax/vehicles/$',     'track.ajax.vehicles'),
  (r'^ajax/positions/$',    'track.ajax.positions'),
  
  # List available vehicles
  (r'^(page(?P<page>[0-9]+)/)?$', 'django.views.generic.list_detail.object_list', vehicle_info_dict),
  
  # Move a vehicle
  (r'^(?P<moveType>(translate|set))/(?P<x>' + coord + r')/(?P<y>' + coord + r')/(' + vehicleRegexp + r'/)?$', 'track.vehicle.move'),
  
  # Itinerary manipulation APIs
  (r'^itinerary/$', 'django.views.generic.list_detail.object_list', itinerary_info_dict),
  
  # Set itinerary for a vehicle
  (r'^itinerary/set/' + vehicleRegexp + '/' + itineraryRegexp + '/', 'track.itinerary.set'),
  
  # Set checkpoints for itinerary
  (r'itinerary/save/' + itineraryRegexp + r'/$', 'track.itinerary.save')
)
